package com.lcc.aop;


import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

@Component  //交给IOC容器管理
@Aspect //表示是AOP程序
@Slf4j
public class TimeAspect {
    //@Around("execution(* com.lcc.service.*.*(..))")
    public Object recordTime(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
        //1. 记录开始时间
        long begin = System.currentTimeMillis();

        //2. 调用原始方法运行
        Object object = proceedingJoinPoint.proceed();//调用原始方法运行

        //3. 记录结束时间
        long end = System.currentTimeMillis();

        log.info(proceedingJoinPoint.getSignature() + "执行耗时：{}ms", end - begin);
        return object;
    }
}
